package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
 * Created by yz on 2018/7/17
 */
class UserColumnDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def update(userId: Int, siteNameInfo: String): Future[Unit] = db.run(UserColumn.filter(_.userId === userId).
    map(_.selectColumns).update(siteNameInfo)).map(_ => ())

  def insertOrUpdate(row: UserColumnRow) = db.run(UserColumn.insertOrUpdate(row)).map(_ => ())

  def selectOption(userId: Int) = db.run(UserColumn.filter(_.userId === userId).result.
    headOption)


}
